<% content_for(:left) do %>
  <dt><span class="content"><%=t(:users, :scope => [:navigation, :mainnavigation]) %></span></dt>
  <dd>
    <ul class="selectlist">
    		<li>
    			<%= link_to t(:left_header, :scope => [:user,:index]), "#" , :class => "selected" %>
    		</li>
    </ul>
  </dd>
<% end %>

<dl id="contentPanel" class="panel">
  <dt id="contentHeaderPanel">
    <span class="content">
      <% if current_user.allow?(:user_create) %>
        <%= link_to(
              button_text(:add),
              new_skyline_user_path,
              :remote => true,
              :method => :get,
              :class => "button small right",
              :style => "margin-top: 3px; visibility:visible;") %>
      <% end %>

      <%= t(:header, :scope => [:user, :index], :count => @users.total_entries) %>
    </span>
  </dt>
  <dd id="contentBodyPanel">
    <div id="contentEditPanel" class="panel">
        <table class="listing" id="userListing">
          <thead>
            <tr>
              <th style="width: 25%"><%= Skyline::User.human_attribute_name("email") %></th>
              <th style="width: 25%"><%= Skyline::User.human_attribute_name("name") %></th>
              <th style="width: 15%"><%= Skyline::User.human_attribute_name("role") %></th>
              <th style="width: 15%"><%= Skyline::User.human_attribute_name("created_at") %></th>
              <th style="width: 20%">&nbsp;</th>
            </tr>
          </thead>
          <tbody>
            <% @users.each do |u| %>
              <tr class="<%= cycle("odd","even") %>">
                <td><%= u.email %></td>
                <td><%= u.name %></td>
                <td><%= u.roles.map{|s| t(s.name, :scope => [:user,:roles], :default => s.name) }.to_sentence %></td>
                <td><%= u.created_at.present? ? l(u.created_at, :format => :long) : "" %></td>
                <td class="right">
                  <% if current_user.allow?(:user_update) %>
                    <%= link_to button_text(:edit), edit_skyline_user_path(u), :class => "button small edit" %>
                  <% end %>

                  <% if current_user.allow?(:user_delete) %>
                    <%= link_to(
                          button_text(:delete),
                          skyline_user_path(u,:page => params[:page]),
                          :remote => true,
                          :method => :delete,
                          :confirm => t(:confirm_destroy, :scope => [:user,:index], :display_name => u.display_name),
                          :class => "button #{@current_user == u ? "disabled" : "red"} small") %>
                  <% end %>

                </td>
              </tr>
            <% end %>
          </tbody>
        </table>
        <script type="text/javascript" charset="utf-8">
          (function(){
            var t = new Skyline.Table("userListing", {draggable: false});
            // Make sure the contentPanel resizes our table!
            $('contentEditPanel').addComponentEvent("skyline.layout","resize",function(panel,w,h){
              $('userListing').retrieve("skyline.table").resize(w, "100%");
            });

            t.addEvent("selectRow",function(row,event){
              if($(event.target).match("a:not(.edit),button,input[type=submit]") || $(event.target).getParent("a:not(.edit),button,input[type=submit]")){
                return;
              }
              event.stop();
              row.addClass("selected");
              var l = row.getElement("a.edit");
              if(l){
                (new Application.Request({url : l.getProperty("href")})).get();
              }
            });

            t.addEvent("deselectRow",function(row){
              row.removeClass("selected");
            });
          })();
        </script>
    </div>
  </dd>
  <% if @users.total_pages > 1 %>
    <dd id="contentFooterPanel" class="footer">
    	<div class="content">
    	  <%= will_paginate @users %>
      </div>
    </dd>
  <% end %>
</dl>